package com.amon.amonplayer.rxjava.schedulder;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

public class AndroidSchedulers {

    static final Schedulers MAIN_THREAD = new HandlerScheduler(new Handler(Looper.getMainLooper()));

    public static Schedulers mainThread() {
        return MAIN_THREAD;
    }

    private static class HandlerScheduler extends Schedulers {
        private final Handler handler;

        public HandlerScheduler(Handler handler) {
            this.handler = handler;
        }

        @Override
        public void scheduleDirect(Runnable runnable) {
            Message message = Message.obtain(handler, runnable);
            handler.sendMessageDelayed(message, 0);
        }
    }
}
